package com.myspace.views;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ScrollView;

public class MSScrollView extends ScrollView
{
   	public MSScrollView(Context context)
   	{
   		super(context);
   	}

   	public MSScrollView(Context context, AttributeSet attrs)
  	{
   		super(context, attrs);
  	}

   	public MSScrollView(Context context, AttributeSet attrs, int defStyle)
  	{
   		super(context, attrs, defStyle);
  	}

   	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
	{
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);

		View child = getChildAt(0);
		LinearLayout childLayout = null;
		
		if (LinearLayout.class.isInstance(child)) {
			childLayout = (LinearLayout)child;
		}
		
		if (childLayout == null){
			return;
		}

		if (getMeasuredHeight() - getPaddingTop() - getPaddingBottom() > childLayout.getMeasuredHeight()) {
			ViewGroup.LayoutParams layoutParams = childLayout.getLayoutParams();
			layoutParams.height = LinearLayout.LayoutParams.FILL_PARENT;
			childLayout.setLayoutParams(layoutParams);
			childLayout.requestLayout();
			childLayout.measure(MeasureSpec.makeMeasureSpec(MeasureSpec.EXACTLY, childLayout.getMeasuredWidth()), MeasureSpec.makeMeasureSpec(MeasureSpec.EXACTLY, getMeasuredHeight() - getPaddingTop() - getPaddingBottom()));
			}
	}
}
